#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <readline/readline.h>
#include <readline/history.h>

char fis[20][20];

void cmd_chmod(char *comm)
{
	char *c;
	mode_t mod;
	int i=1,j,ok_v,ok_R,ch;
	c = strtok (comm, " ");
	mod = (mode_t) strtok (NULL, " ");
	while ((c = strtok (NULL, " ")) != NULL)
	{
		if (strcmp (c, "-v") == 0)
			ok_v = 1;
		else if (strcmp (c, "-R") == 0)
			ok_R = 1;
		else if ((strcmp (c, "-Rv") == 0) || (strcmp (c, "-vR") == 0))
		{
			ok_R = 1;
			ok_v = 1;
		}
		else 
		{
			strcpy (fis[i], c);
			i++;
		}
	}
	i--;
	if (i)
		for (j = 1; j <= i; j++)
			chmod(fis[i],mod); 
	else
		fprintf (stderr, "error!\n");
}

int main()
{
	char *comm;
	comm = readline ("command: ");
	cmd_chmod(comm);
	return 0;
}
